//
//  DKRepayAgreementFootView.m
//  DanKU
//
//  Created by EDY on 2023/11/10.
//

#import "DKRepayAgreementFootView.h"
#import "DKOrderRepayViewController.h"
@implementation DKRepayAgreementFootView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame: frame]) {
        self.backgroundColor =  DK_Hex(@"#FAFAFA");
       
    }
    return self;
}

-(void)setType:(NSInteger)Type{
    if (Type == 0) {
        [self creatAgreement];
    }else{
        [self creatMore];
    }
}

-(void)creatAgreement{
    UIButton * dk_HomeAgreementBtn = [[UIButton alloc] init];
    [dk_HomeAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_HomeAgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_HomeAgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_HomeAgreementBtn addTarget:self action:@selector(Agreement) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_HomeAgreementBtn];
    [dk_HomeAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}

#pragma mark UIButton Action
-(void)RepayAction{
    DKOrderRepayViewController *repay = [DKOrderRepayViewController new];
//        repay.orderNo = self.dateSouce.orderNo;
    repay.dateSouce = self.dataSource;
    [[self viewController].navigationController pushViewController:repay animated:YES];
}

-(void)Agreement{
    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
    [self.viewController.navigationController pushViewController:dk_WebViewCtrl animated:YES];
}

-(void)creatMore{
    UIButton * dk_HomeStartBtn = [[UIButton alloc] init];
    [dk_HomeStartBtn setTitle:@"Repay" forState:UIControlStateNormal];
    [dk_HomeStartBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_HomeStartBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_HomeStartBtn setBackgroundColor:DK_Hex(@"#4566FF")];
    dk_HomeStartBtn.layer.cornerRadius = DK_IsWidthScale(25);
    [dk_HomeStartBtn addTarget:self action:@selector(RepayAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_HomeStartBtn];
    [dk_HomeStartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self).offset(DK_IsWidthScale(30));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    
    
    UIButton * dk_HomeAgreementBtn = [[UIButton alloc] init];
    [dk_HomeAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_HomeAgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_HomeAgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_HomeAgreementBtn addTarget:self action:@selector(Agreement) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_HomeAgreementBtn];
    [dk_HomeAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_HomeStartBtn.mas_bottom).offset(20);
        make.centerX.equalTo(self);
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}

//获取View所在的Viewcontroller方法
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

@end
